package cn.wolfcode.luowowo.acticle.service.impl;

import cn.wolfcode.luowowo.acticle.domain.Strategy;
import cn.wolfcode.luowowo.acticle.domain.Region;
import cn.wolfcode.luowowo.acticle.domain.StrategyContent;
import cn.wolfcode.luowowo.acticle.mapper.StrategyContentMapper;
import cn.wolfcode.luowowo.acticle.mapper.StrategyMapper;
import cn.wolfcode.luowowo.acticle.mapper.RegionMapper;
import cn.wolfcode.luowowo.acticle.query.StrategyQueryObject;
import cn.wolfcode.luowowo.acticle.service.IStrategyService;
import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * 大攻略服务实现类
 */
@Service
public class StrategyServiceImpl implements IStrategyService {
    @Autowired
    private StrategyMapper strategyMapper;
    @Autowired
    private StrategyContentMapper strategyContentMapper;
    //查询所有大攻略
    @Override
    public PageInfo query(StrategyQueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(), qo.getPageSize());
        List<Strategy> list = strategyMapper.selectForList(qo);
        return new PageInfo(list);
    }

    //删除大攻略
    @Override
    public void delete(Long id) {
        strategyMapper.deleteByPrimaryKey(id);
    }

    @Override
    public void saveOrUpdate(Strategy strategy) {
        if(strategy.getId() != null){
            strategyMapper.updateByPrimaryKey(strategy);
        }else{
            strategyMapper.insert(strategy);
        }
    }

    @Override
    public List<Strategy> listAll() {
        return strategyMapper.selectAll();
    }

    /**
     * 根据id获取大攻略
     * @param sid
     * @return
     */
    @Override
    public Strategy get(Long sid) {

        return strategyMapper.selectByPrimaryKey(sid);
    }

}
